package com.netty.coder;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class StringEncoder extends MessageToByteEncoder<String> {

	@Override
	public void encode(ChannelHandlerContext ctx, String msg, ByteBuf out)
			throws Exception {	    
		byte[] b = msg.getBytes("utf-8");		
		out.writeInt(b.length);
		out.writeBytes(b);
	}

}
